package afaas.framework.dal.mysql;

import afaas.framework.util.entity.ResultSupport;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface DataService {
    
    ResultSupport<Boolean> registeredSQLStatement(String tableName);

    ResultSupport<Set<String>> tableColumns(String tableName);
    
    ResultSupport<List<Map<String, Object>>> select(String tableName, Map<String, Object> selectParams);

    ResultSupport<List<Map<String, Object>>> select(String tableName, Map<String, Object> selectParams, String templateName, Set<String> specifiedColumns);

    ResultSupport<Long> selectCount(String tableName, Map<String, Object> selectParams);

    ResultSupport<Long> update(String tableName, Map<String, Object> updateParams);
    
    ResultSupport<Long> insert(String tableName, Map<String, Object> insertParams);
    
    ResultSupport<Long> delete(String tableName, int id);

    interface PreparedStatementExecutor<T> {
        ResultSupport<T> call(PreparedStatement preparedStatment) throws SQLException;
    }
    
    class DataServiceModeCode{
        
        public static final String Execute = "Execute";
        
        public static final String ExecuteUpdate = "ExecuteUpdate";
        
        public static final String ExecuteQuery = "ExecuteQuery";
        
        public static final String GetResult = "GetResult";
    }
    
    class DataServiceResultCode{
        
        public static final String NormalCode = "NormalCode";
        
        public static final String PreparedStatementSetObjectException = "PreparedStatementSetObjectException";
        
        public static final String PreparedStatementExecutorException = "PreparedStatementExecutorException";
        
        public static final String PreparedStatementOrConnectionCloseException = "PreparedStatementOrConnectionCloseException";
        
        public static final String ExecuteUpdateException = "ExecuteUpdateException";
        
        public static final String ExecuteQueryException = "ExecuteQueryException";
        
        public static final String GetResultException = "GetResultException";
        
    }
    
}
